package com.example.rabbitmq.limit;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

import java.io.IOException;

/**
 * @author weiyx
 * @date 2021-01-16
 */
public class MyConsumer extends DefaultConsumer {

    private Channel channel;

    public MyConsumer(Channel channel) {
        super(channel);
        this.channel = channel;
    }

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties basicProperties,  byte[] body) throws IOException {
        System.out.println("----- consumer message -----");
        System.out.println("consumerTag = " + consumerTag);
        System.out.println("envelope = " + envelope);
        System.out.println("basicProperties = " + basicProperties);
        System.out.println("body = " + new String(body));
        //手动签收
        channel.basicAck(envelope.getDeliveryTag(), false);
    }
}
